<template>
  <XtxDialog v-model:visible="visibleDialog" title="查看物流">
    <template v-slot:body>
      <div v-if="logistics" class="order-logistics-goods">
        <a class="image" href="javascript:;">
          <img v-lazy="logistics.picture" alt="">
          <p>{{ logistics.count }}件商品</p>
        </a>

        <div class="info">
          <p><span>配送企业: </span>{{ logistics.company.name }}</p>
          <p><span>快递单号: </span>{{ logistics.company.number }}</p>
          <p><span>联系电话: </span>{{ logistics.company.tel }}</p>
        </div>
      </div>

      <div v-if="logistics && logistics.list.length > 0" class="order-logistics-list">
        <div v-for="(item, index) in logistics.list" :key="item.id" class="item">
          <div :class="{active: index === 0}" class="line"></div>
          <div class="logistics">
            <p>{{ item.text }}</p>
            <p>{{ item.time }}</p>
          </div>
        </div>
      </div>
    </template>
  </XtxDialog>
</template>

<script>

import { ref } from 'vue'
import API from '@/api/order'

export default {
  name: 'OrderLogistics',
  setup() {
    const visibleDialog = ref(false)

    // 物流信息
    const logistics = ref(null)

    // 打开对话框
    const open = (order) => {
      visibleDialog.value = true

      // 查询物流
      API.logisticsOrder(order.id)
          .then((res) => {
            logistics.value = res.result
          })
    }

    return {
      visibleDialog,
      open,
      logistics
    }
  }
}
</script>

<style lang="less" scoped>
.xtx-dialog {
  ::v-deep .wrapper {
    width: 680px;
  }
}

.order-logistics-goods {
  display: flex;
  align-items: center;
  height: 130px;
  padding: 0 20px;
  margin-bottom: 20px;

  background-color: #f5f5f5;
  font-size: 14px;

  .image {
    width: 92px;
    height: 92px;
    border: 1px solid #e4e4e4;
    position: relative;

    img {
      width: 100%;
      height: 100%;
    }

    p {
      position: absolute;
      width: 100%;
      height: 20px;
      line-height: 20px;
      left: 0;
      bottom: 0;

      color: #ffffff;
      background-color: rgba(0, 0, 0, .5);
      text-align: center;
    }
  }

  .info {
    flex: 1;
    padding-left: 20px;
    line-height: 30px;

    p {
      span {
        color: #999;
      }
    }
  }
}

.order-logistics-list {
  position: relative;
  padding-top: 10px;
  font-size: 14px;

  .item {
    display: flex;

    &:last-child {
      .line {
        border-color: transparent;

        &::before {
          top: 0;
        }
      }
    }

    .line {
      width: 27px;
      border-right: 2px solid #f5f5f5;
      margin-right: 25px;
      position: relative;

      &::before {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        width: 12px;
        height: 12px;

        background: #e4e4e4;
        transform: translate(7px, 0);
        border-radius: 50%;
      }

      &.active {
        &::before {
          background: @xtxColor;
          z-index: 1;
        }

        &::after {
          content: "";
          position: absolute;
          top: 0;
          right: 0;
          width: 20px;
          height: 20px;

          transform: translate(11px, -4px);
          border-radius: 50%;
          background: #e3f9f4;
        }
      }
    }

    .logistics {
      flex: 1;
      padding-bottom: 35px;
      position: relative;
      top: -3px;

      p {
        &:first-child {
          color: #666;
        }

        &:last-child {
          color: #999;
          margin-top: 6px;
        }
      }
    }
  }
}
</style>
